package configx

import "github.com/spf13/viper"

var C *Config

type Config struct {
	App     AppConfig     `mapstructure:"app"`
	Mysql   MysqlConfig   `mapstructure:"mysql"`
	Token   TokenConfig   `mapstructure:"token"`
	Static  StaticConfig  `mapstructure:"static"`
	Shybot  ShybotConfig  `mapstructure:"shybot"`
	BackEnd BackEndConfig `mapstructure:"backend"`
}

type AppConfig struct {
	Debug bool `mapstructure:"debug"`
}

type MysqlConfig struct {
	Dns string `mapstructure:"dns"`
}

type TokenConfig struct {
	Key string `mapstructure:"key"`
}

type StaticConfig struct {
	Scheme string `mapstructure:"scheme"`
	Host   string `mapstructure:"host"`
}

type ShybotConfig struct {
	Token string `mapstructure:"token"`
}

type BackEndConfig struct {
	Host string `mapstructure:"host"`
}

// Init 初始化配置
func Init(path string) error {
	viper.SetConfigFile(path)
	if err := viper.ReadInConfig(); err != nil {
		return err
	}
	if err := viper.Unmarshal(&C); err != nil {
		return err
	}
	return nil
}
